package dfsketches.gr3d;

import java.util.Hashtable;

//import dfsketches.bicycles.Hashtable;

public class Triangle {

	final static float eps = 0.001f;
	
	Vertex a;
	Vertex b;
	Vertex c;
	int color;
	
	public Triangle(Vertex va, Vertex vb, Vertex vc, int col) {
		a = va;
		b = vb;
		c = vc;
		color = col;
	}

	public Triangle(Triangle tri) {
		a = new Vertex(tri.a);
		b = new Vertex(tri.b);
		c = new Vertex(tri.c);
		color = tri.color;
	}

	public Triangle() {
		a = new Vertex();
		b = new Vertex();
		c = new Vertex();
	}
	
	public void copy(Triangle t) {
		a.copy(t.a);
		b.copy(t.b);
		c.copy(t.c);
		color = t.color;
	}

	public void apply(Matrix3D m) {
		a.apply(m);
		b.apply(m);
		c.apply(m);
	}
	
	public void applyBones(Hashtable<Vertex, InstanceBone> verticesToBones, Triangle prototri) {
		a.apply(verticesToBones.get(prototri.a).transformation);
		b.apply(verticesToBones.get(prototri.b).transformation);
		c.apply(verticesToBones.get(prototri.c).transformation);
	}

	public void tcopy(Triangle t) {
		a.tcopy(t.a);
		b.tcopy(t.b);
		c.tcopy(t.c);
		color = t.color;
	}

	public void complexApply(Hashtable<Vertex, Matrix3D> verticesToMatrices) {
		if (!a.t) {
			a.t = true;
			a.tApply(verticesToMatrices.get(a));
		}
		if (!b.t) {
			b.t = true;
			b.tApply(verticesToMatrices.get(b));
		}
		if (!c.t) {
			c.t = true;
			c.tApply(verticesToMatrices.get(c));
		}
	}
	
	public String toString() {
		return "[(" + a.x + ", " + a.y + ", " + a.z + "), " +
				"(" + b.x + ", " + b.y + ", " + b.z + "), " +
				"(" + c.x + ", " + c.y + ", " + c.z + ")] -> [" + 
				"(" + a.x + ", " + a.y + ", " + a.z + "), " +
				"(" + b.x + ", " + b.y + ", " + b.z + "), " +
				"(" + c.x + ", " + c.y + ", " + c.z + ")] : " + color;
	}
	
}